package nl.gamayun.whohasit;

import android.content.Context;
import android.content.res.Resources;

public enum TYPE {
	lent_to(0),
	lent_from(1);

	private int type;
	private String[] values;

	private TYPE(int type) {
		this.type = type;
		Context context = WhoHasIt.getContext();
		Resources resources = context.getResources();
		values = resources.getStringArray(R.array.types_array); 
	}

	public int getType()
	{
		return type;
	}
	
	public String getTypeAsString()
	{
		return type+"";
	}
	
	public String getTypeValue() 
	{
		return values[type];
	}

	public static TYPE getType(String code) {
		for (TYPE type : TYPE.values()) {
			if (code != null && code.equals(type.getTypeAsString()))
				return type;
		}
		return null;
	}

	public static TYPE getTypeByValue(String value) {
		for (TYPE type : TYPE.values()) {
			if (value != null && value.equals(type.getTypeValue()))
				return type;
		}
		return null;
	}

	@Override
	public String toString() {
		return getTypeValue();
	}
}
